{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "408c7cc1",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-04-11T12:27:25.228143Z",
     "start_time": "2022-04-11T12:27:25.008257Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.cb84829cf4729a7fe9a0875d160a1aa5.315360000.1965040046.282335-25946039', 'expires_in': 2592000, 'session_key': '9mzdWThkrtubyT7VMDr7XwXbLnGxNhfAAh9cCapiHB0zda52o/UOr8y6eLBdGxOqipH0sDfVEjjIJgjsatfJmbBgvQ8gjw==', 'access_token': '24.bbe0ecde3565af88ada7e9fdfe5a7092.2592000.1652272046.282335-25946039', 'scope': 'public vis-ocr_ocr brain_ocr_scope brain_ocr_general brain_ocr_general_basic vis-ocr_business_license brain_ocr_webimage brain_all_scope brain_ocr_idcard brain_ocr_driving_license brain_ocr_vehicle_license vis-ocr_plate_number brain_solution brain_ocr_plate_number brain_ocr_accurate brain_ocr_accurate_basic brain_ocr_receipt brain_ocr_business_license brain_solution_iocr brain_qrcode brain_ocr_handwriting brain_form brain_ocr_passport brain_ocr_vat_invoice brain_numbers brain_ocr_business_card brain_ocr_train_ticket brain_ocr_taxi_receipt vis-ocr_household_register vis-ocr_vis-classify_birth_certificate vis-ocr_台湾通行证 vis-ocr_港澳通行证 vis-ocr_机动车购车发票识别 vis-ocr_机动车检验合格证识别 vis-ocr_车辆vin码识别 vis-ocr_定额发票识别 vis-ocr_保单识别 vis-ocr_机打发票识别 vis-ocr_行程单识别 brain_ocr_vin brain_ocr_quota_invoice brain_ocr_birth_certificate brain_ocr_household_register brain_ocr_HK_Macau_pass brain_ocr_taiwan_pass brain_ocr_vehicle_invoice brain_ocr_vehicle_certificate brain_ocr_air_ticket brain_ocr_invoice brain_ocr_insurance_doc brain_formula brain_seal brain_ocr_facade brain_ocr_meter brain_doc_analysis brain_ocr_webimage_loc brain_ocr_medical_paper brain_ocr_doc_analysis_office brain_vat_invoice_verification brain_ocr_medical_detail brain_vehicle_registration_certificate brain_ocr_online_taxi_itinerary brain_ocr_multi_idcard brain_ocr_mixed_multi_vehicle brain_ocr_weigth_note brain_ocr_ multiple_invoice wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online', 'session_secret': '55a16840526138bf67cf2788567c850a'}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests \n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=H6d31uMatSZsMhmR0nZ55NGp&client_secret=39ajUPYfGVEs82I0rYW8zk58S9CL7s7s'\n",
    "response = requests.get(host)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "4f467737",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-04-11T12:27:28.350191Z",
     "start_time": "2022-04-11T12:27:28.345140Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'24.bbe0ecde3565af88ada7e9fdfe5a7092.2592000.1652272046.282335-25946039'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ZXY_at = response.json()['access_token']\n",
    "ZXY_at"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "fb816a9f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-04-11T12:27:33.330379Z",
     "start_time": "2022-04-11T12:27:32.404138Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'words_result': [{'words': '5G通信技术发展视域下物联网产业链发展问题研究←'}, {'words': '摘要：随着科技的迅迅发展，5G通信现在越来越深入到生活中，人们也越来越需'}, {'words': '要5G的支持，本篇将对物联网与5G技术进行分析后在叙述他们之间的关系。←'}, {'words': '关键词：物联网产业链、5G通信技术←'}, {'words': '·41.什么是物联网产业链←'}, {'words': '现在社会，物联网早已经随处可见，发展趋势也将会更加多元，并且，它的'}, {'words': '广泛率将越来越高。通过人与机器的混合通信，能够让流量的发展更加迅速。不'}, {'words': '过，在这之间，对于人们的使用感来说，高效，便捷，安全访问，共享信息是很'}, {'words': '重要的四个方面。现代生活中，物联网和各种高新创作应用的持续出现，让许许'}, {'words': '多多的互联网设备有了极大的优势，再这样子的情况中，将会出现空前绝有的对'}, {'words': '多元化的要求与和无线连接性有所关联的应用的场景。它们能够推动我国经济政'}], 'words_result_num': 11, 'log_id': 1513493962688910636}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "通用文字识别（高精度版）\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('words.png', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token = ZXY_at\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "62a9855d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-04-11T12:28:06.094948Z",
     "start_time": "2022-04-11T12:28:04.896122Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'codes_result': [{'text': ['https://u.wechat.com/EO5co775KWcAjyMXHxxw5nM'], 'type': 'QR_CODE'}, {'text': ['10432761'], 'type': 'UPC_E'}], 'codes_result_num': 2, 'log_id': 1513494100120857982}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "二维码识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/ocr/v1/qrcode\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('erweima.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token = ZXY_at\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "ed33b912",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-04-11T12:27:57.031045Z",
     "start_time": "2022-04-11T12:27:55.986861Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'result': {'valid_date': '88/88', 'bank_card_number': '6225 7688 8888 8888', 'bank_name': '招商银行', 'bank_card_type': 2, 'holder_name': 'XLAO ZHAO'}, 'direction': 0, 'log_id': 1513494063605230929}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "银行卡识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/ocr/v1/bankcard\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('yhk.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token = ZXY_at\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "407fff38",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.4"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
